/**
 * Created by hank-leihan on 16/11/21.
 */
gotodetail = function(des, obj) {
    mui.openWindow({
        url: des,
        extras: {
            fakeid: $(obj).data("fakeid")
        }
    });
};
gotoshequn = function(des, obj) {

    mui.openWindow({
        url: des,
        extras: {
            postid: $(obj).data("postid")
        }
    });
}

var ajax_skill,text_skill='',num_skill,fakeid,time_sub,x_index='',x_text;
addlist_search = function(data,obj,num) {
//            A护工 B小组 C诊所 D地区社群 E兴趣社群
    if( num == "A"){
        //护工
        for(var key in data) {
            num_skill = data[key].skill.split(',').length;
            for(var x = 0;x<=num_skill;x++){
                ajax_skill = data[key].skill.split(',')[x-1];
                if(ajax_skill == undefined || ajax_skill == "undefined"){
                    continue;
                }else{
                    ajax_skill = '<span>'+ajax_skill+'</span>';
                    text_skill+=ajax_skill;
                }
            }
            fakeid = num+'888'+data[key].id;
            // var dom = '<li class="search_box" data-fakeid ="' + fakeid + '" onclick="gotodetail(\'sub_find_tieba_hugong.html\',this)">' +
            var dom = '<li class="search_box" data-fakeid ="' + fakeid + '">' +
                '<a href="javascript:void(0);">' +
                '<img class="mui-media-object mui-pull-left" src="' + data[key].headurl + '">' +
                '<div class="search_body">' +
                '<p class="Title_Name">'+data[key].name+'</p>' +
                '<p class="Title_Text">' +
                '<span class="Title_Text_Content">已为<i>130</i>位用户提供优质服务位用户提供优质服务</span>' +
                '</p>' +
                '<p class="Title_Title">'+text_skill+'</p>' +
                '</div>' +
                '</a>' +
                '</li>';

            //var dom2 = '<li class="mui-table-view-cell mui-media hospital-list" data-fakeid="' + data[key].fakeid + '" onclick="gotodetail(\'sub_find_tieba.html\',this)">' +

            $(obj).append(dom);
            text_skill = '';

        }

    }else if( num == "B" ){
        //小组
        for(var key in data) {
            num_skill = data[key].skill.split(',').length;
            for(var x = 0;x<=num_skill;x++){
                ajax_skill = data[key].skill.split(',')[x-1];
                if(ajax_skill == undefined || ajax_skill == "undefined"){
                    continue;
                }else{
                    ajax_skill = '<span>'+ajax_skill+'</span>';
                    text_skill+=ajax_skill;
                }
            }
            fakeid = num+'888'+data[key].id;
            // var dom = '<li class="search_box" data-fakeid ="' + fakeid + '" onclick="gotodetail(\'sub_find_tieba_xiaozu.html\',this)">' +
            var dom = '<li class="search_box xiaozu_box" data-fakeid ="' + fakeid + '">' +
                '<a href="javascript:void(0);">' +
                '<div class="v2 add_img_img"><img class="mui-media-object mui-pull-left" src="' + data[key].headurl + '"></div>' +
                '<div class="search_body">' +
                '<p class="Title_Name">'+data[key].name+'</p>' +
                '<p class="Title_Text" style="height:10px;">' +
                '</p>' +
                '<p class="Title_Title">'+text_skill+'</p>' +
                '</div>' +
                '</a>' +
                '</li>';

            //var dom2 = '<li class="mui-table-view-cell mui-media hospital-list" data-fakeid="' + data[key].fakeid + '" onclick="gotodetail(\'sub_find_tieba.html\',this)">' +

            $(obj).append(dom);
            text_skill = '';

        }

        //添加绑定事件
        $('.xiaozu_box').on('tap',function(){
            var url='';
            url = 'sub_find_tieba_xiaozu.html';
            clicked(url+'?fakeid='+$(this).attr('data-fakeid'));

        });

    }else if( num == "C"){

        console.log("this is:"+JSON.stringify(data));
        //诊所
        for(var key in data) {
            num_skill = data[key].skill.split(',').length;
            for(var x = 0;x<=num_skill;x++){
                ajax_skill = data[key].skill.split(',')[x-1];
                if(ajax_skill == undefined || ajax_skill == "undefined"){
                    continue;
                }else{
                    ajax_skill = '<span>'+ajax_skill+'</span>';
                    text_skill+=ajax_skill;
                }
            }
            fakeid = num+'888'+data[key].id;
            // var dom = '<li class="search_box" data-fakeid ="' + fakeid + '" onclick="gotodetail(\'sub_find_tieba.html\',this)">' +
            var dom = '<li class="search_box zhensuo_box" data-fakeid ="' + fakeid + '">' +
                '<a href="javascript:void(0);">' +
                '<div class="v1 add_img_img"><img class="mui-media-object mui-pull-left" src="' + data[key].headurl + '"></div>' +
                '<div class="search_body">' +
                '<p class="Title_Name">'+data[key].name+'</p>' +
                '<p class="Title_Text">' +
                '<span class="Title_Text_Content">'+data[key].serverdetail+'</span>' +
                '</p>' +
                '<p class="Title_Title">'+text_skill+'</p>' +
                '</div>' +
                '</a>' +
                '</li>';

            //var dom2 = '<li class="mui-table-view-cell mui-media hospital-list" data-fakeid="' + data[key].fakeid + '" onclick="gotodetail(\'sub_find_tieba.html\',this)">' +

            $(obj).append(dom);
            text_skill = '';

        }

        //添加绑定事件
        $('.zhensuo_box').on('tap',function(){
            var url='';
                url = 'sub_find_tieba.html';
            clicked(url+'?fakeid='+$(this).attr('data-fakeid'));

        });

    }else if( num == "D" ){
        //地区社群
        for(var key in data) {
            //时间截取
            //for(var pic_num = 0;pic_num<6;pic_num++){
            //    if(data[key].pic[pic_num] != null || data[key].pic[pic_num] != ""){
            //        x_text='<img src="'+data[key].pic[pic_num]+'" alt="">';
            //        x_index+=x_text;
            //    }
            //}
            fakeid = 'A'+data[key].id;
            time_sub = data[key].time.substring(0,16);
            // var dom = '<li class="Tieba_list" onclick="gotoshequn(\'sub_community_tieba_detail.html\',this)" data-postid="'+fakeid+'" class="mui-table-view-cell mui-media">' +
            var dom = '<li class="Tieba_list" data-postid="'+fakeid+'" class="mui-table-view-cell mui-media">' +
                '<a href="javascript:;">' +
                '<img id="listheadurl" class="mui-media-object mui-pull-left" src="'+data[key].headurl+'">' +
                '<div class="mui-media-body">' +
                '<h5 id="listwriter">'+data[key].username+'</h5>' +
                '<h4 id="listtitle">'+data[key].title+'</h4>' +
                //'<p id="summary" class="mui-ellipsis">'+data[key].summary+'</p>' +
                //'<div class="mui_body_img">'+x_index+'</div>' +
                '<p><span id="time">'+time_sub+'</span><span id="discuss" class="mui-icon mui-icon-chatbubble mui-pull-right">'+data[key].commentcount+'</span></p>' +
                '</div>' +
                '</a>' +
                '</li>';
            $(obj).append(dom);
            x_index = ''; x_text='';

        }
    }else if( num == "E" ){
        //兴趣社群
        for(var key in data) {
            //时间截取
            //for(var pic_num = 0;pic_num<6;pic_num++){
            //    if(data[key].pic[pic_num] != null || data[key].pic[pic_num] != ""){
            //        x_text='<img src="'+data[key].pic[pic_num]+'" alt="">';
            //        x_index+=x_text;
            //    }
            //}
            time_sub = data[key].time.substring(0,16);
            fakeid = 'B'+data[key].id;
            // var dom = '<li class="Tieba_list" data-postid="'+fakeid+'" class="mui-table-view-cell mui-media">' +
            var dom = '<li class="Tieba_list" data-postid="'+fakeid+'" class="mui-table-view-cell mui-media">' +
                '<a href="javascript:;">' +
                '<img id="listheadurl" class="mui-media-object mui-pull-left" src="'+data[key].headurl+'">' +
                '<div class="mui-media-body">' +
                '<h5 id="listwriter">'+data[key].username+'</h5>' +
                '<h4 id="listtitle">'+data[key].title+'</h4>' +
                //'<p id="summary" class="mui-ellipsis">'+data[key].summary+'</p>' +
                //'<div class="mui_body_img">'+x_index+'</div>' +
                '<p><span id="time">'+time_sub+'</span><span id="discuss" class="mui-icon mui-icon-chatbubble mui-pull-right">'+data[key].commentcount+'</span></p>' +
                '</div>' +
                '</a>' +
                '</li>';
            $(obj).append(dom);
            x_index = ''; x_text='';

        }
    }else if( num == "F" ){
        //急诊医院
        for(var key in data) {
            num_skill = data[key].skill.split(',').length;
            for(var x = 0;x<=num_skill;x++){
                ajax_skill = data[key].skill.split(',')[x-1];
                if(ajax_skill == undefined || ajax_skill == "undefined"){
                    continue;
                }else{
                    ajax_skill = '<span>'+ajax_skill+'</span>';
                    text_skill+=ajax_skill;
                }
            }
            fakeid = 'D888'+data[key].id;
            // $(obj).append('<li class="mui-table-view-cell mui-media hospital-list hospital-list" data-fakeid ="' + fakeid + '" onclick="gotodetail(\'sub_find_tieba_yiyuan.html\',this)">' +
            $(obj).append('<li class="mui-table-view-cell mui-media hospital-list" data-fakeid ="' + fakeid + '">' +
                '<a href="javascript:void(0);" class="mui-navigate-right">' +
                '<img class="mui-media-object mui-pull-left hospitalImg" src="' + data[key].headurl + '">' +
                '<div class="mui-media-body my-box">' +
                '<p class="Title_Name">'+data[key].name+'</p>' +
                '<p class="mui-ellipsis Title_Text">电话:'+data[key].phone+'</p>' +
                '<p class="mui-ellipsis Title_Text">地址:'+data[key].serverdetail+'</p>' +
                '<p class="Title_Title">'+text_skill+'</p>' +
                '</div>' +
                '</a>' +
                '</li>');

            text_skill = '';
        }

        //添加绑定事件
        $('.hospital-list').on('tap',function(){
            var url='';
            url = 'sub_find_tieba_yiyuan.html';
            clicked(url+'?fakeid='+$(this).attr('data-fakeid'));

        });

    }

};


gotoerror = function() {

    var dom = '<div style="text-align:center;margin-top:30px;color:grey;"> \
						关注加载中...请下拉刷新\
					</div>';
    $("#spread").append(dom);

}

